package appapi.controller.oider;

import appapi.Request.Basic.OperTypeReq;
import appapi.common.ResponseBean;
import appapi.entity.basic.OperatingTypeEntity;
import appapi.service.OperatingtypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 作业类别接口
 *
 * @author luocheng
 * @version 1.0
 * @date 2023/05/26 11:22
 */
@Api(tags = "作业类别")
@RestController
@RequestMapping("/api/operatingType")
public class OperatingTypeController {

    private static final Logger logger = LoggerFactory.getLogger(OperatingTypeController.class);
    @Autowired
    private OperatingtypeService operatingtypeService;
    /**
     * 列表
     */
    @GetMapping("/getList")
    @ApiOperation(value = "获取列表")
    public ResponseBean<OperatingTypeEntity> list(@Valid OperTypeReq req) {
        try {
            List<OperatingTypeEntity> dataList = operatingtypeService.getList(req);
            return ResponseBean.success(dataList);
        } catch (Exception e) {
            logger.error("获取列表异常", e);
            return ResponseBean.fail("获取列表异常");
        }
    }

    /**
     * 信息
     */
    @GetMapping("/getDetail")
    @ApiOperation(value = "获取详情")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "operTypeId", dataType = "long", value = "类别ID",required = true)
    })
    public ResponseBean<OperatingTypeEntity> detail(Long operTypeId) {
        try {
            if (operTypeId == null) {
                return ResponseBean.fail("ID不能为空");
            }
            OperatingTypeEntity entity = operatingtypeService.getDetail(operTypeId);
            if (entity != null) {
                return ResponseBean.success(entity);
            } else {
                return ResponseBean.fail("未查询到记录");
            }
        } catch (Exception e) {
            logger.error("获取详情异常", e);
            return ResponseBean.fail("获取详情异常");
        }
    }
}
